1. Field of the Invention
The invention relates to computing systems and, more particularly, to multithreaded processing systems.
2. Description of the Related Art
Modern optimizing compilers have the ability to do a large number of complex optimizations. Some types of optimization are universal and may improve performance in virtually all cases. However, in other cases, the benefit of optimizations, or the manner in which they need to be applied for maximum benefit, depends on the target program's behavior. In order to address optimizations that may depend on a target program's behavior, various approaches have been used.
One approach that has been used to optimize code in view of a program's behavior is “static analysis”. FIG. 1 depicts one embodiment of the static analysis approach. Using this approach, a source program (block 100) is created. The compiler analyzes the program to determine its behavior and optimizes accordingly (block 110). During the analysis, the compiler determines or guesses at program behavior and makes optimizations. Finally, an optimized executable is produced (block 120). This approach may be relatively easy for the user compared to some other approaches, but is limited in applicability because static analysis generally cannot accurately determine program behavior in many cases. Therefore, optimization opportunities may not be fully exploited.
FIG. 2 depicts another compiler optimization approach sometimes utilized that is referred to as “profile feedback”. The profile feedback approach acknowledges some of the deficiencies of the static analysis approach, and utilizes a “training run” to learn about a target program's behavior. Using this approach, developers build a training version of a program. As shown in FIG. 2, a source program is provided (block 200) and compiled (block 210). The resulting executable is built for the sole purpose of training. Training runs are then performed (block 220) using training inputs (block 230). After training, the source code is re-built (block 240) and a new executable created (block 250) which is optimized based upon the training runs. While a training run may help the compiler learn about the program's behavior, the build process requires extra steps. For this reason, many developers avoid profile feedback. In addition, training input might not represent actual input. Further, optimizations are fixed in the final executable and do not adapt to variations in program behavior.
Yet another approach used for optimizing program code is “run time optimization”. Using the run time optimization approach, a program's behavior is monitored during runtime. Based upon the observed behavior, code may be optimized and re-optimized as desired. FIG. 3 illustrates one embodiment of this approach. As shown, a source program (block 300) is compiled (block 310) and training runs may be performed (block 320). Such training runs may utilize training input (block 330). Finally, an executable is produced (block 340). During runtime (block 350), a monitor (block 360) is utilized to monitor the execution. Based upon this runtime monitoring, the code may be re-compiled (block 370) in an effort to further optimize the code. Re-compilation produces a new executable (block 340). The process (350, 360, 370) may then be repeated as desired.
In this run time optimization approach, the original executable may be built with a traditional compiler. While the run time optimization approach may provide for some adaptability during runtime, it does have some drawbacks. For example, monitoring introduces additional overhead. Further, because run time optimization is designed to work on any executable, it doesn't know what parts to monitor for a given behavior in an executable. Consequently, it may end up monitoring many things in many places that are not particularly relevant. Still further, re-compilation is very complex and resource-hungry. Another potential problem for run time optimization is that certified code may be modified during execution. Consequently, the executable can no longer be trustworthy. For these and other reasons, traditional run time optimization may not be desirable.
In view of the above, effective methods and mechanisms for improving code optimization are desired.